import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import Store from 'electron-store'

// 初始化
const localStore = new Store({})

const api = {}


if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
    contextBridge.exposeInMainWorld('localStore', {
      get: (key) => localStore.get(key),
      set: (key, value) => localStore.set(key, value),
      delete: (key) => localStore.delete(key),
    })


  } catch (error) {
    console.error(error)
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI
  // @ts-ignore (define in dts)
  window.api = api
  // @ts-ignore (define in dts)
  window.localStore = localStore
}
